package Lee_code;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author blh
 * @date 2024年07月03日 10:18
 */
public class Lee_739_73 {
    public int[] dailyTemperatures(int[] temperatures) {
        int len = temperatures.length;
        int[] res = new int[len];
        res[len - 1] = 0;
        Deque<Integer> deque = new LinkedList<>();
        deque.push(0);
        for (int i = 1; i < len; i++) {
            while (!deque.isEmpty() && (temperatures[i] > temperatures[deque.peek()])) {
                res[deque.peek()] = i - deque.peek();
                deque.pop();
            }
            deque.push(i);
        }
        return res;
    }
}
